package com.arrogames.blondbattle.xml 
{
	import com.arrogames.blondbattle.model.UnitDefinition;
	import com.arrogames.blondbattle.model.WeaponDefinition;
	import feathers.data.ListCollection;
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class UnitParser {
		
		[Embed(source = "../../../../../resources/config/units.xml", mimeType="application/octet-stream")]
		static private const UnitsXML:Class; 
		
		static public function parse():Array {
			var xml:XML = new XML(new UnitsXML());
			
			var retval:Array = [];
			
			for each (var unitXML:XML in xml.unit) {
				var unit:UnitDefinition = new UnitDefinition();
				unit.name = unitXML.name;
				unit.textureName = unitXML.textureName;
				unit.health = parseFloat(unitXML.health);
				unit.speed = parseFloat(unitXML.speed);
				
				unit.costs = parseFloat(unitXML.purchase.costs);
				unit.cooldown = parseFloat(unitXML.purchase.cooldown);
				
				var weapon:WeaponDefinition = new WeaponDefinition();
				weapon.damage = parseFloat(unitXML.weapon.damage);
				weapon.reload = parseFloat(unitXML.weapon.reload);
				weapon.speed = parseFloat(unitXML.weapon.speed);
				weapon.range = parseFloat(unitXML.weapon.range);
				
				unit.weapon = weapon;
				retval.push(unit);
			}
			
			return retval;
		}
		
	}

}